import { dateFormat } from '@vimi/utils-tool'

export const enumServiceType = {
  1: '三农',
  2: '创业创新企业',
  3: '战略性新型产业',
  4: '其他',
}

export const tableColumns = [
  { attrs: { label: '贷款类型', prop: 'use_category', align: 'center', minWidth: 120 } },
  {
    attrs: {
      label: '银行借款（授信）合同号',
      prop: 'ensurce_contract',
      align: 'center',
      minWidth: 120,
    },
  },
  {
    attrs: { label: '被担保人', align: 'center', minWidth: 120 },
    columns: [
      { attrs: { label: '受保企业', prop: 'customer_name', align: 'center', minWidth: 120 } },
      { attrs: { label: '企业性质', prop: 'org_class_name', align: 'center', minWidth: 120 } },
      { attrs: { label: '登记所在地', prop: 'address_detail', align: 'center', minWidth: 120 } },
      {
        attrs: {
          label: '所属行业',
          prop: 'parent_industrial_class',
          align: 'center',
          minWidth: 120,
        },
      },
      {
        attrs: { label: '上一年度营业收入 ', prop: 'sale_income', align: 'center', minWidth: 120 },
      },
      {
        attrs: { label: '上一年末资产总额', prop: 'assets_funds', align: 'center', minWidth: 120 },
      },
    ],
  },
  {
    attrs: {
      label: '被担保人划型（小微、三农/其他）',
      prop: 'warrantee_category',
      align: 'center',
      minWidth: 140,
    },
  },
  { attrs: { label: '担保项目投向', prop: 'project_invest', align: 'center', minWidth: 140 } },
  {
    attrs: {
      label: '扶持农村12个特色产业',
      prop: 'industrial_class',
      align: 'center',
      minWidth: 140,
    },
  },
  { attrs: { label: '贷款银行（支行）', prop: 'bank_name', align: 'center', minWidth: 140 } },
  { attrs: { label: '银行贷款金额', prop: 'confirm_reply_funds', align: 'center', minWidth: 140 } },
  { attrs: { label: '贷款利率（%）', prop: 'load_rate', align: 'center', minWidth: 140 } },
  {
    attrs: { label: '同期基准利率（%）', prop: 'same_period_rate', align: 'center', minWidth: 140 },
  },
  { attrs: { label: '担保责任余额', prop: 'left_funds', align: 'center', minWidth: 140 } },
  { attrs: { label: '保证合同号', prop: 'gua_contract', align: 'center', minWidth: 140 } },
  {
    attrs: { label: '担保责任开始日', prop: 'load_date', align: 'center', minWidth: 140 },
    process: v => dateFormat(v, 'yyyy/MM/dd'),
  },
  { attrs: { label: '担保责任到期日', prop: 'load_end_date', align: 'center', minWidth: 140 } },
  { attrs: { label: '担保费率（%）', prop: 'warranty_rate', align: 'center', minWidth: 140 } },
  { attrs: { label: '银行分险比例（如有）', prop: 'risk_rate', align: 'center', minWidth: 140 } },
  {
    attrs: {
      label: '当地政府是否建立风险补偿机制',
      prop: 'is_risk_mech',
      align: 'center',
      minWidth: 140,
    },
    process: v => (v === 1 ? '是' : '否'),
  },
  {
    attrs: {
      label: '当地政府预算安排风险补偿金（如有）',
      prop: 'risk_comps_funds',
      align: 'center',
      minWidth: 140,
    },
  },
  {
    attrs: {
      label: '地方政府补偿比例（如有）',
      prop: 'comps_rate',
      align: 'center',
      minWidth: 140,
    },
  },
  {
    attrs: { label: '服务对象类型', prop: 'service_object_type', align: 'center', minWidth: 140 },
    process: v => enumServiceType[v],
  },
  {
    attrs: {
      label: '带动当地建档立卡贫困户（户）',
      prop: 'poverty_households',
      align: 'center',
      minWidth: 140,
    },
  },
  {
    attrs: {
      label: '是否属于绿色扶贫产业项目',
      prop: 'is_poverty_project',
      align: 'center',
      minWidth: 140,
    },
    process: v => (v === 1 ? '是' : '否'),
  },
  { attrs: { label: '备注', prop: 'remark', align: 'center', minWidth: 140 } },
]

export const fields = [
  'customer_related_id',
  ...tableColumns.reduce((pre, cur) => {
    const { attrs, columns } = cur
    if (columns) {
      pre.push(...columns.map(it => it.attrs.prop))
    } else {
      pre.push(attrs.prop)
    }
    return pre
  }, []),
]

export const dataAdapter = item => {
  item.is_risk_mech = +item.is_risk_mech
  item.is_poverty_project = +item.is_poverty_project
  item.confirm_reply_funds = +item.confirm_reply_funds
  return item
}
